#include <REGX52.H>
#include "OneWire.h"

#define DS18B20_SKIP_ROM        0xCC //跳过ROM
#define DS18B20_CONVERT_T       0x44 //开始温度变化
#define DS18B20_READ_SCRATCHPAD 0xBE //读暂存器


/**
  * @brief  温度变化数据祯
  * @param  
  * @retval 
  */
void DS18B20_ConvertT(void){
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_CONVERT_T);
}

/**
  * @brief  
  * @param  
  * @retval 
  */
float DS18B20_ReadT(void){
	unsigned char TLSB,TMSB;
	int Temp;
	float T;
	OneWire_Init();
	OneWire_SendByte(DS18B20_SKIP_ROM);
	OneWire_SendByte(DS18B20_READ_SCRATCHPAD);
	TLSB=OneWire_ReceiveByte();
	TMSB=OneWire_ReceiveByte();
	Temp=(TMSB<<8)|TLSB;//合并
	T=Temp/16.0;
	return T;
} 